package com.ajx.todo.uiexplorer;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.ajx.abui.dialog.EmptyView;
import com.ajx.todo.R;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lai on 2017/9/9.
 */

public class UIExplorerFragment extends Fragment{

    private RecyclerView rvExampleList;
    private List<String> uies =new ArrayList<>();
    private ExampleAdapter adapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.frag_example, container, false);
        rvExampleList = ((RecyclerView) inflate.findViewById(R.id.rv_example_list));
        rvExampleList .setLayoutManager(new GridLayoutManager(getContext(),4));
        adapter = new ExampleAdapter(uies);
        rvExampleList.setAdapter(adapter);
        ((EmptyView) inflate.findViewById(R.id.ev)).setOnErrorClickListener(new EmptyView.OnErrorClickListener() {
            @Override
            public void onErrorClick() {
                Toast.makeText(getContext(), "error", Toast.LENGTH_SHORT).show();
            }
        });
        return inflate;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        uies.clear();
        uies.add("button");
        uies.add("dialog");
        uies.add("text");
        uies.add("text");
        uies.add("text");
        uies.add("loading");
        uies.add("empty");
        uies.add("other");

        adapter.notifyDataSetChanged();
    }

    class ExampleAdapter extends BaseQuickAdapter<String,BaseViewHolder>{
        public ExampleAdapter(@Nullable List<String> data) {
            super(R.layout.item_example_title,data);
        }

        @Override
        protected void convert(BaseViewHolder helper, String item) {
            helper.setText(R.id.tv_example_title,item);
        }
    }
}
